package com.aatattoo.light_food_service.config.error;

import com.aatattoo.light_food_service.enumeration.ReturnCode;
import com.aatattoo.light_food_service.utils.TimeUtil;
import lombok.Data;

@Data
public class ResultData<T> {
    /**
     * 结果状态 ,具体状态码参见ResultData.java
     */
    private int code;
    private String message;
    private T data;
    private String requestTime;


    public ResultData() {
        this.requestTime = TimeUtil.stampToDate(System.currentTimeMillis());
    }


    public static <T> ResultData<T> success(T data) {
        ResultData<T> resultData = new ResultData<>();
        resultData.setCode(ReturnCode.RC200.getCode());
        resultData.setMessage(ReturnCode.RC200.getMessage());
        resultData.setData(data);
        return resultData;
    }

    public static <T> ResultData<T> fail(int code, String message) {
        ResultData<T> resultData = new ResultData<>();
        resultData.setCode(code);
        resultData.setMessage(message);
        return resultData;
    }

    public static <T> ResultData<T> success(T data,ReturnCode code,String msg) {
        ResultData<T> resultData = new ResultData<>();
        resultData.setCode(code.getCode());
        resultData.setMessage(msg);
        resultData.setData(data);
        return resultData;
    }




}
